package com.lhz.project.system.controller.base;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.lhz.common.page.ResponseObject;
import com.lhz.framework.aspect.log.annotation.SysLog;
import com.lhz.framework.security.annotation.CheckPermission;
import com.lhz.project.system.model.param.auth.LoginLogParam;
import com.lhz.project.system.model.param.auth.OperateLogParam;
import com.lhz.project.system.model.vo.auth.LoginLogVo;
import com.lhz.project.system.model.vo.auth.OperateLogInfoVo;
import com.lhz.project.system.model.vo.auth.OperateLogVo;
import com.lhz.project.system.service.base.LogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LiHuaZhi
 * @since 2020-06-23 17:02:26
 */
@Tag(name = "日志管理")
@RestController
@RequestMapping("log")
@ApiSort(35)
public class LogController {

    @Resource
    private LogService logService;

    @Operation(summary = "根据Id查询操作", description = "根据Id查询操作")
    @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = OperateLogInfoVo.class))))
    @ApiOperationSupport(order = 5)
    @SysLog(model = "日志管理", name = "根据Id查询操作")
    @GetMapping("operate/{id}")
    @CheckPermission(code = "system:operate:query")
    public ResponseObject selectByPrimaryKey(@PathVariable("id") String id) {
        Object obj = logService.selectByPrimaryKey(id);
        return ResponseObject.success(obj);
    }

    @Operation(summary = "查询操作日志", description = "查询操作日志")
    @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = OperateLogVo.class))))
    @ApiOperationSupport(order = 10)
    @SysLog(model = "日志管理", name = "查询操作日志")
    @GetMapping("operate")
    @CheckPermission(code = "system:operate:query")
    public ResponseObject listOperateLog(@ParameterObject OperateLogParam param) {
        Object obj = logService.listOperateLog(param);
        return ResponseObject.success(obj);
    }

    @Operation(summary = "查询登录日志", description = "查询登录日志")
    @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = LoginLogVo.class))))
    @ApiOperationSupport(order = 15)
    @SysLog(model = "日志管理", name = "查询登录日志")
    @GetMapping("login")
    @CheckPermission(code = "system:login:query")
    public ResponseObject listLoginLog(@ParameterObject LoginLogParam param) {
        Object obj = logService.listLoginLog(param);
        return ResponseObject.success(obj);
    }
}